<!-- Destination Address Field -->
<label class="col-sm-3 control-label text-left" for="destination-address">
    <span id="destination-address-label">Destination</span>
    <a href="#" data-toggle="tooltip" title='This is the destination address you would like to use' class="pull-right" id="destination-address-tooltip"><i class="fa fa-lg fa-question-circle-o margin-top-5" ></i></a>
</label>            
<div class="col-sm-9">
    <div class="input-group">
        <input type="text" class="form-control" name="destination" id="destination-address" placeholder="Destination Address" autocomplete="off" data-minlength="24" required >
        <a class="input-group-addon" id="destination-address-book" data-toggle="tooltip" title='<div class="nowrap">Address Book</div>'><i class="fa fa-book"></i></a>
    </div>
</div>

<script>
$(document).ready(function(){

    // Get the current form type and tooltip
    var type = getFormType(),
        tip  = $('#destination-address-tooltip');

    // Change the look/feel of the form based on form type
    // if(type=='send'){
    //     // do something here
    // } else if(type=='issue-supply'){
    //     // do something elese here
    // }

    if(type=='dispenser'){
        $('#destination-address-label').text('Dispenser');
        $('#destination-address').attr('placeholder','Dispenser Address')
        // Set destination address to current wallet address
        $('#destination-address').val(FW.WALLET_ADDRESS);
    }

    // Wait a brief moment to allow things to initialize
    setTimeout(function(){

        // Change toolip text based on form type 
        var txt = false;
        if(type=='send')
            txt = 'This is the address which will be receiving funds from you';
        if(type=='transfer-ownership')
            txt = 'This is the address which you are transferring token ownership to';
        if(type=='dispenser')
            txt = 'This is the address where the dispenser will be setup';
        if(txt)
            tip.attr('data-original-title',txt);

    },750);

    // Do some additional cleanup and checks on destination
    $('#destination-address').change(function(){
        var me   = $(this),
            addr = String(me.val()).trim();
        // If a valid address was not entered, try to lookup destination using username or asset name
        if(!isValidAddress(addr) && addr.length >= 4){
            var asset = addr.toUpperCase();
            // Detect USER.BTC usernames and translate to BTCTAG.USER asset name
            if(addr.toUpperCase().endsWith('.BTC'))
                asset = 'BTCTAG.' + addr.toUpperCase().replace(/\.BTC/i,'');
            // Try to lookup asset and then use owner address as destination address
            $.getJSON(FW.EXPLORER_API + '/api/asset/' + asset, function(o){
                if(o.owner)
                    me.val(o.owner);
            });
        } else {
            me.val(addr);
        }
        // Handle updating the transaction fee based on actual tx size
        if(type=='sweep'||type=='send')
            updateTransactionSize();
    });

    // Display 'Address Book' when user clicks address book link
    $('#destination-address-book').click($.debounce(100,function(e){
        dialogComingSoon();
    }));

});
</script>